home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST.C < prev    next >
C/C++ Source or Header  |  1992-08-11  |  2KB  |  68 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12. // Created: LGO 11/27/89 -- Initial design
  13. // Updated: JAM 08/10/92 -- just #include <iostream.h> intead of stream.*
  14. // Updated: JAM 08/11/92 -- anach. form() replaced with iomanips
  15. //
  16.  
  17. #include <iostream.h>
  18. #include <iomanip.h>
  19.  
  20. static int num_test;
  21. static int tests_passed;
  22. static int tests_failed;
  23. static char* test_name;
  24.  
  25. void test_start(char* name = NULL) {
  26.   num_test = 0;
  27.   tests_passed = 0;
  28.   tests_failed = 0;
  29.   test_name = name;
  30.   cout << "-----------------------------------------------------------------------------\n";
  31.   cout << "Start Testing";    
  32.   if (test_name != NULL) cout << " " << test_name;
  33.   cout << ":\n-----------------------------------------------------------------------------\n";
  34.   cout.flush();
  35.  }
  36.  
  37. void test_begin(const char* msg) {
  38.   num_test++;
  39.   cout << " Test " << setfill('0') << setw(3) << num_test << setfill(' ') << ": "
  40.          << setiosflags(ios::right) << setw(53) << msg << " --> ";
  41.   cout.flush();
  42. }
  43.  
  44. // NOTE: We don't pass in the message (see test_begin) because
  45. //       we want to ensure that the message is printed BEFORE
  46. //       the test is executed.  This way when a test crashes
  47. //       we can tell if it was during a test, or between tests.
  48. void test_perform(int success) {
  49.   if (success) {
  50.     tests_passed++;
  51.     cout << "  PASSED\n";
  52.   } else {
  53.     tests_failed++;
  54.     cout << "**FAILED**\n";
  55.   }
  56.   cout.flush();
  57. }
  58.  
  59. void test_summary() {
  60.   cout << "-----------------------------------------------------------------------------\n";
  61.   if (test_name != NULL) cout << test_name << " ";
  62.   cout << "Test Summary: ";
  63.   cout << tests_passed << " passed, " << tests_failed << " failed";
  64.   if (tests_failed > 0) cout << "\t\t\t*****";
  65.   cout << "\n-----------------------------------------------------------------------------\n";
  66.   cout.flush();
  67. }
  68.